-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TECompiler] Decouple TE compute and schedule lowering in ScheduleBuilder #10561
Conversation
f21f8f4
to
669a1f7
Compare
auto outputs = lower_te_compute.Lower(prim_func, [&](std::string name) { return name; }); | ||
return CachedFunc(tgt, GlobalVar(lower_te_compute.candidate_name_), lower_te_compute.fn_inputs_, | ||
outputs, te::Schedule(), tir::PrimFunc(), {}, | ||
IRModule(Map<GlobalVar, BaseFunc>({})), lower_te_compute.constant_tensors_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @mbaret for this change
669a1f7
to
a167655
Compare
int LowerToTECompute::const_index = 0; | ||
|
||
// Construct a schedule for a given Relay primitive function and target. | ||
class ScheduleBuilder : ExprVisitor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could give this class a better name while we are doing this cleanup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit hard to come up with a good name since this class does a lot more than "schedule building". See https://github.com/apache/tvm/pull/10561/files#r824096015
Over time we stuffed all lowering-dependent tasks onto this class...
use_auto_scheduler_ = backend::IsAutoSchedulerEnabled(); | ||
} | ||
|
||
CachedFunc Create(const Function& relay_func, std::function<std::string(std::string)> renamer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you are refactoring this code it might be good to better annotate it with comments describing the pieces here as now this code (due to me and Mark refactoring) has quite a few branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this function is not only used for ordinary lowering purposes, but also abused for ansor / meta schedule task extraction or "apply history best" depending on where it is called...
Optional<ObjectRef> opt_mod_or_base_func = meta_schedule::MetaScheduleContext::QueryInsideWithScope
is very opaque since (1) we don't know if it returns anything and (2) we don't what concrete value it returns.
After my task extraction refactor, QueryInsideWithScope
can always return a non-null, concrete Schedule
object, since the None
case is used only for task extraction currently. cc @junrushao1994
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per discussion with Masa, we decided to just clean up meta_schedule/integration.cc
and make it clearer
Overall looks great Masa thanks for doing this! |
a167655
to
8e4f69e
Compare
8e4f69e
to
4cd3a16
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @masahi! All look good to me! Just a few nits
use_auto_scheduler_ = backend::IsAutoSchedulerEnabled(); | ||
} | ||
|
||
CachedFunc Create(const Function& relay_func, std::function<std::string(std::string)> renamer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per discussion with Masa, we decided to just clean up meta_schedule/integration.cc
and make it clearer
…lder (apache#10561) * Decouple TE compute and schedule lowering in ScheduleBuilder * fixed merge conflict * removed create_schedule stuff * add public, fix include path convention * Forgot visiting arg in ScheduleBuilder CallNode vsit * fixed anchor impl selection
Refactors
ScheduleBuilder
, that currently does TE compute lowering and schedule application in one go, into two classes.The motivation is to use the TE compute lowering class,
LowerToTECompute
, for meta schedule task extraction. For task extraction, there is no need to apply and lower schedules, but currently we doVMCompiler.lower()
which is too hacky and overkill.@mbs-octoml @junrushao1994 @jroesch @comaniac